package top.go2do.common.utils;

import cn.hutool.core.lang.Snowflake;
import cn.hutool.core.util.IdUtil;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

/**
 * @Description
 * @Author xingyj
 * @CreateTime 2025/3/24 12:54
 */
@Component
public class IdUtils {
    @Value("${custom.datacenterId:1}")
    private Integer datacenterId;

    @Value("${custom.machineId:1}")
    private Integer machineId;

    public Long getSnowflakeId() {
        // 创建 Snowflake 实例，传入数据中心 ID 和机器 ID
        Snowflake snowflake = IdUtil.createSnowflake(machineId, datacenterId);
        return snowflake.nextId();
    }
}
